#include <51func.h>
int main(int argc, char *argv[])
{
    // ./6_transfile_A 1.pipe file1
    ARGS_CHECK(argc,3);
    int fd_pipe = open(argv[1],O_WRONLY);
    int fd_file = open(argv[2],O_RDWR);
    // 发文件名
    // 先发长度 再发内容
    int length = strlen(argv[2]);
    write(fd_pipe,&length,sizeof(int));
    write(fd_pipe,argv[2],strlen(argv[2]));
    
    // 发文件的内容
    char buf[4096];
    while(1){
        memset(buf,0,sizeof(buf));
        ssize_t sret = read(fd_file,buf,sizeof(buf));
        if(sret == 0){
            length = 0;
            write(fd_pipe,&length,sizeof(int));
            break;
        }
        length = sret;
        write(fd_pipe,&length,sizeof(length));
        write(fd_pipe,buf,length);
    }
    close(fd_file);
    close(fd_pipe);
    return 0;
}

